﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace RangeScrollControls
{
	public partial class SingleSrollBar : UserControl
	{
		private int lastLeft, lastRight;
		public Brush Background
		{
			get
			{
				return innerControl.Background;
			}
			set
			{
				innerControl.Background = value;
			}
		}

		public Brush TrackBrush
		{
			get
			{
				return innerControl.TrackBrush;
			}

			set
			{
				innerControl.TrackBrush = value;
			}
		}

		public Brush SliderBrush
		{
			get
			{
				return innerControl.SliderBrush;
			}
			set
			{
				innerControl.SliderBrush = value;
			}
		}
		public int Value
		{
			get
			{
				return innerControl.LeftValue;
			}
			set
			{
				innerControl.LeftValue = innerControl.RightValue = value;
				OnValueChanged();
			}
		}
		public int Min
		{
			get
			{
				return innerControl.Min;
			}
			set
			{
				innerControl.Min = value;
			}
		}
		public int Max
		{
			get
			{
				return innerControl.Max;
			}
			set
			{
				innerControl.Max = value;
			}
		}

		public double Width
		{
			get
			{
				return innerControl.Width;
			}
			set
			{
				innerControl.Width = value;
			}
		}
		public double Height
		{
			get
			{
				return innerControl.Height;
			}
			set
			{
				innerControl.Height = value;
			}
		}

		public event EventHandler ValueChanged;
		protected void OnValueChanged()
		{
			if (lastLeft != innerControl.LeftValue)
				innerControl.RightValue = innerControl.LeftValue;
			else if (lastRight != innerControl.RightValue)
				innerControl.LeftValue = innerControl.RightValue;
			
			if (ValueChanged != null)
			{
				ValueChanged(this, new EventArgs());
			}
			lastLeft = lastRight = innerControl.LeftValue;
		}

		private void innerControl_ValueChanged(object sender, EventArgs e)
		{
			OnValueChanged();
		}

		public SingleSrollBar()
		{
			InitializeComponent();
			innerControl.LeftValue = innerControl.RightValue = 0;
			lastLeft = lastRight = 0;
			innerControl.HideRight();
		}
	}
}
